using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MIMPGameLibrary;
using System.Collections.ObjectModel;

namespace MIMPWinForms.Forms
{
    /// <summary>
    /// A form that allows the user to choose which players should see sent chat messages.
    /// </summary>
    public partial class ChatModeSelector : Form
    {
        /// <summary>
        /// Gets the chat mode currently set by the user.
        /// </summary>
        public Constants.ChatModes Mode {
            get {
                if (rdbtnEveryone.Checked) return Constants.ChatModes.Yell;
                else if (rdbtnTeam.Checked) return Constants.ChatModes.Say;
                else return Constants.ChatModes.Whisper;
            }
        }

        /// <summary>
        /// If the "Custom" button is checked, returns a list of all players who have been selected to hear the
        /// chat message. If it is not checked, or if no players are selected, returns an empty list.
        /// </summary>
        public List<Player> SelectedPlayers {
            get { return selected; }
        }
        private List<Player> selected;

        public ChatModeSelector(ReadOnlyCollection<Player> players) {
            InitializeComponent();
            selected = new List<Player>();
            foreach (Player p in players) {
                chklstPlayers.Items.Add(p);
            }
            this.Closing += new CancelEventHandler(ChatModeSelector_Closing);
        }

        /// <summary>
        /// Do not close the form when the user clicks the X. Just hide it.
        /// </summary>
        void ChatModeSelector_Closing(object sender, CancelEventArgs e) {
            if (sender == this) {
                e.Cancel = true;
                this.Hide();
            }
        }

        private void rdbtnCustom_CheckedChanged(object sender, EventArgs e) {
            chklstPlayers.Enabled = rdbtnCustom.Checked;

            if (rdbtnCustom.Checked) {
                foreach (object p in chklstPlayers.Items) {
                    selected.Add((Player)p);
                }
            } else {
                selected.Clear();
            }
        }
    }
}